/*
 * @Author: lizhijie429
 * @Date: 2021-08-10 18:47:21
 * @LastEditors: lizhijie429
 * @LastEditTime: 2021-09-14 18:25:02
 * @Description:
 */
import { InjectionKey } from "vue";
import { createStore, useStore as baseUseStore, Store } from "vuex";

// 为 store state 声明类型
export interface State {
  count: number;
}

// 定义 injection key
export const key: InjectionKey<Store<State>> = Symbol();

// 创建一个新的 store 实例
export const store = createStore<State>({
  state() {
    return {
      count: 0,
    };
  },
  mutations: {
    increment(state) {
      state.count++;
    },
  },
});

// 定义自己的 `useStore` 组合式函数
export const useStore = () => {
  return baseUseStore(key);
};
